import http from "@/api";
import { ResPage } from "@/api/interface/index";
import { Applet } from "@/api/interface/iot";
import { ContentTypeEnum } from "@/enums/httpEnum";

export const getShowAppletList = (params: Applet.ReqUserApplet) => {
	return http.get<ResPage<Applet.ReqUserApplet[]>>(`/service/app/show/find`, params);
};
export const getMarketAppletList = (params: Applet.ReqUserApplet) => {
	return http.get<ResPage<Applet.ReqUserApplet[]>>(`/service/app/market/find`, params);
};
export const getUserAppletList = (params: Applet.ReqUserApplet) => {
	return http.get<ResPage<Applet.ReqUserApplet[]>>(`/app/find`, params);
};
export const getUserAppletDetail = (params: Applet.ReqUserApplet) => {
	return http.get<Applet.ReqUserApplet>(`/service/app/get`, params);
};
export const addUserApplet = (params: Applet.ResUserApplet) => {
	return http.post(`/service/app/add`, params);
};
export const delUserApplet = (params: Applet.ResUserApplet) => {
	return http.post(`/service/app/remove`, params);
};
export const modUserApplet = (params: Applet.ResUserApplet) => {
	return http.post(`/service/app/modify`, params);
};
export const findAppletInstanceList = (params: Applet.ResUserApplet) => {
	return http.get<any>(`/service/app/instance/find`, params);
};
export const modAppletInstance = (params: Applet.ReqApplet) => {
	return http.post(`/service/app/instance/modify`, params);
};
export const delAppletInstance = (params: Applet.ReqApplet) => {
	return http.post(`/service/app/instance/remove`, params);
};
export const addAppletInstance = (params: Applet.ReqApplet) => {
	return http.post(`/service/app/instance/add`, params);
};
export const getAppletInstance = (params: Applet.ReqApplet) => {
	return http.get<any>(`/service/app/instance/get`, params);
};
export const marketPublish = (params: Applet.ReqApplet) => {
	return http.post<any>(`/service/app/market/publish`, params);
};
export const marketWithdraw = (params: Applet.ReqApplet) => {
	return http.post<any>(`/service/app/market/withdraw`, params);
};
export const marketInstall = (params: Applet.ReqApplet) => {
	return http.post<any>(`/service/app/market/install`, params);
};
export const upgradeInstance = (params: Applet.ReqApplet) => {
	return http.post<any>(`/service/app/instance/upgrade`, params);
};
//添加应用
export const addApp = (params: any) => {
	return http.post<any>(`/app/add`, params);
};
//应用列表
export const getAppList = (params: any) => {
	return http.get<any>(`/app/find`, params);
};
//应用详情
export const getApp = (params: any) => {
	return http.get<any>(`/app/get`, params);
};
//修改应用
export const modApp = (params: any) => {
	return http.post<any>(`/app/modify`, params);
};
//删除应用
export const delApp = (params: any) => {
	return http.post<any>(`/app/remove`, params);
};
//启动服务
export const startAppService = (params: any) => {
	return http.post<any>(`/app/service/start`, params);
};
//资源列表
export const getResourceList = (params?: any) => {
	return http.get<any>(`/app/resource/find`, params);
};
//服务日志
export const getAppServiceLog = (params: any) => {
	return http.get<any>(`/app/service/log/get`, params);
};
//服务列表
export const getAppServiceList = (params: any) => {
	return http.get<any>(`/app/service/find`, params);
};
//服务详情
export const getAppService = (params: any) => {
	return http.get<any>(`/app/service/get`, params);
};
//停止服务
export const stopAppService = (params: any) => {
	return http.post<any>(`/app/service/stop`, params);
};
//修改服务
export const modAppService = (params: any) => {
	return http.post<any>(`/app/service/modify`, params);
};
//保存资源
export const saveAppResource = (params: any) => {
	let formData = new FormData();
	for (let key in params) {
		if (params[key]) {
			formData.append(key, params[key]);
		}
	}
	return http.post<any>(`/app/resource/save`, formData, { Headers: { "Content-Type": ContentTypeEnum.FORM_DATA } });
};
//修改资源
export const modAppResource = (params: any) => {
	return http.post<any>(`/app/resource/modify`, params);
};
//删除资源
export const delAppResource = (params: any) => {
	return http.post<any>(`/app/resource/remove`, params);
};
//下载资源
export const downloadAppResource = (params: any) => {
	return http.downloadGet(`/app/resource/download`, params, { responseType: "blob" });
};
